package com.zhc.dejingapi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhc.dejingapi.common.result.Result;
import com.zhc.dejingapi.entity.QuestionOptionEntity;
import com.zhc.dejingapi.mapper.QuestionOptionMapper;
import com.zhc.dejingapi.service.QuestionOptionService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhc
 * @since 2024-10-28
 */
@Service
public class QuestionOptionServiceImpl extends ServiceImpl<QuestionOptionMapper, QuestionOptionEntity> implements QuestionOptionService {

    @Resource(name = "mySqlQFlowJdbcTemplate")
    private JdbcTemplate qflowJdbcTemplate;
    @Override
    public Result getInvName() {
        String sql="SELECT form_id from form where app_key=?";
        int formId = qflowJdbcTemplate.queryForObject(sql, Integer.class, "8n1fdhts0o01");
        //String sql1="SELECT form.form_id,form.app_key,form.form_title,question.que_id,question.que_title,question.que_type FROM form JOIN question ON form.form_id = question.form_id WHERE form.app_key = ? AND question.que_title = ?";
        String sql1="SELECT que_id from question where que_title=? and form_id=?";
        long  invNameQueId= qflowJdbcTemplate.queryForObject(sql1, Long.class, "存货名称",formId);
        long invNamePullQueId = qflowJdbcTemplate.queryForObject(sql1, Long.class, "存货名称下拉",formId);
        String sql2="SELECT DISTINCT value from data where form_id=? AND que_id=? ORDER BY value";
        List<String> invNameList= qflowJdbcTemplate.queryForList(sql2, String.class,formId,invNameQueId);
        String sql3="SELECT  str_value from question_option where que_id=?";
        List<String> invNamePullList= qflowJdbcTemplate.queryForList(sql3, String.class,invNamePullQueId);

        //TODO  下拉框回写轻流接口对接
        for(String invName:invNameList){
            if(!invNamePullList.contains(invName)){
                invNamePullList.add(invName);
            }else {
                invNamePullList.remove(invName);
            }
        }
        return Result.ok(invNamePullList);
    }
}
